<?php
class Post extends AppModel {
    var $name = 'Post';
    
    var $order='Post.created DESC';
    
    
    var $hasAndBelongsToMany = array(
        'Degree' => array(
            'className' => 'Degree', 
            'unique' => true,
        ),
        'Spec' => array(
            'className' => 'Spec', 
            'unique' => true,
        ) 
    );
    
    //var $hasMany = array('Media'=>array('className'=>'Media','foreignKey'=>'foreign_key_id'));
    
    
    var $belongsTo = array(
        'Category' => array(
            'className' => 'Category',
            'counterCache' => true,
            'counterScope' => array('Post.status' => 'published'),
        ),
        'District' => array(
            'className' => 'District',
            'counterCache' => true,
            'counterScope' => array('Post.status' => 'published'),
        ),
        'User'
    
    );
    
    
    
  
    var $validate = array(
        'name' => array(
            'notEmpty' => array(
                'rule' => array('notEmpty'),
                'required' => true,
                'message' => 'this field is required!'
            ),
            
        ),
        
        
              
    );
    
    
    /*function paginate($conditions, $fields, $order, $limit, $page = 1, $recursive = null, $extra = array()) {
        
        if (!empty($extra['contain'])) $contain = $extra['contain'];
        
        if(!empty($extra['paginateCache'])) $pagination = Cache::read($extra['paginateCache'].'-'.$page, 'default');
        if (empty($pagination)) :
            $pagination = $this->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive', 'group', 'contain'));
            if(!empty($extra['paginateCache'])) :
                Cache::write($extra['paginateCache'].'-'.$page, $pagination, 'default');
            endif;
        else :
            $ids = Set::extract('{n}.Post.id', $pagination);
            $options = array(
                'conditions' => array('Post.id' => $ids),
                'recursive' => 1,
                'fields' => array('comment_count', 'views'),
                'order' => $order,
            );
            $fresh = $this->find('all', $options);
            for($i=0; $i < $limit; ++$i) :
                $pagination[$i]['Post'] = am($pagination[$i]['Post'], $fresh[$i]['Post']);
            endfor;
        endif;
        return $pagination;
    }
 
    function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        
        $default = array('paginateCache' => false, 'discardJoins' => false);
        $extra = am($default, $extra);
        
        if (!empty($extra['contain'])) $contain = $extra['contain'];
 
        if(!empty($extra['paginateCache'])) $paginationcount = Cache::read($extra['paginateCache'].'_count', 'default');
        if(isset($extra['discardJoins']) && $extra['discardJoins']) $contain = false;
        
        if (empty($paginationcount)) :
            $paginationcount = $this->find('count', compact('conditions', 'contain', 'recursive'));
            if(!empty($extra['paginateCache'])) Cache::write($extra['paginateCache'].'_count', $paginationcount, 'default');
        endif;
        return $paginationcount;
    }*/
    
    
}    
?>